from django.db import models
from common.db import DbModel
from account.models import Users
from products.models import Product
# Create your models here.

class Cart(models.Model):
    """购物车模型"""
    user = models.ForeignKey(Users, on_delete=models.CASCADE, verbose_name='用户')
    product = models.ForeignKey(Product, on_delete=models.CASCADE, verbose_name='商品')
    added_at = models.DateTimeField(auto_now_add=True, verbose_name='加入购物车的时间')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='商品单价')
    quantity = models.PositiveIntegerField(verbose_name='商品数量')
    product_name = models.CharField(max_length=255, verbose_name='商品名称')
    product_image = models.ImageField(blank=True, null=True, verbose_name='商品图标')
    is_active = models.BooleanField(default=True, verbose_name='是否展示这条记录')

    class Meta:
        db_table = 'cart'
        verbose_name = '购物车表'
        verbose_name_plural = '购物车表'

    def __str__(self):
        return f'{self.user.username} - {self.product_name}'